/*
linux_lidar.h
offer lidar data from linux board function api
designed by lunanting


---------------------
2020-12-17 15:05:54
create file
---------------------
*/
#ifndef __LINUX_LIDAR_H
#define __LINUX_LIDAR_H


#include "../../bsp/base_type.h"
#include "../../../include/aos/hal/uart.h"
#include "aos/kernel.h"



// io define
#define LIDAR_blow_io       11

#define LIDAR_io_touch      0
#define LIDAR_io_release    1

//lidar blow time : s
#define LIDAR_blow_time     3

#define LIDAR_blow_cycle_time   100     // ms

typedef enum{
    LIDAR_MODE_MEASURE_DIST = 0,  //正常测距模式
    LIDAR_MODE_MEASURE_ANGLE,     //测量角度模式
    LIDAR_MODE_PARK_GUIDE,        //停车引导模式
    LIDAR_MODE_CAR_DETECT,        //检测是否有车模式
    LIDAR_MODE_CAR_PROFILE,       //车辆轮廓测绘模式

    LIDAR_MODE_MEASURE_DIST_ROOF = 10,  //洗车顶时的测距模式，雷达算法需要扣掉被毛刷挡住的部分
    LIDAR_MODE_MAX
}LIDAR_ALGORITHM_MODE;

/*****************************************data type define**************************/
//point coordinate
typedef struct{
    int x;  //x value
    int y;  //y value
}LIDAR_ponit_coordinate;

//angle point 
typedef struct{
    LIDAR_ponit_coordinate p1;    //近点
    LIDAR_ponit_coordinate p2;    //远点
}LIDAR_angle_point;

//car park status
typedef struct{
    int parking;    //停车引导信息
    int parked;     //停车引导完成状态
}LIDAR_park_msg;

//lidar data
typedef struct{
    u8 xp[2];
    u8 crc;
    u8 corner;  //cornor flag 1=corner,0=normal
    u8 minDis;     //min distace cm
    u8 minDis2;     //min distace cm
    u8 minDis3;     //避障区域距离
    u8 maxHight;   //max hight cm
    u8 lidar_valid;    //lidar valid state 0=normal
    u8 camera_valid;   //camera valid state 0=normal
    u8 ss_valid;       //supersonic valid state 0=normal
    u8 data_valid;     //data valid 1=nvalid,0=not valid
    LIDAR_angle_point angle_point;    //待机点 计算角度端点 
    LIDAR_park_msg park;    //park status
}LIDAR_data;


// location point
typedef struct{
    int x;
    int y;
    float angle;
}LIDAR_location;

//linux lidar 
typedef struct{
    int init;   //init state,0=no init
    int error;  //机器报错，0=没错误
    int do_angle;//算法模式，参考LIDAR_ALGORITHM_MODE
    int blow;   //blow cycle count
    int blow_hold_time; //blow time
    int blow_io;    //blow io pin number
    int lidar_lost; //lost status,0=normal,1=lost
    aos_mutex_t mux;
    uart_dev_t uart;    //uart obj
    LIDAR_data msg;   //lidar data
    LIDAR_location location;
}LINUX_lidar;


/******************************************function extern**************************/
extern int xp_linux_lidar_init(int port,int speed); //linux lidar module init

extern int xp_linux_lidar_dis_get(void);    //get lidar min dis
extern int xp_linux_lidar_dis2_get(void);    //get lidar min dis
extern int xp_linux_lidar_dis3_get(void);   //get lidar min dis3
extern int xp_linux_lidar_valid_get(void);  //get lidar valid status

extern int xp_linux_lidar_hight_get(void);  //get lidar max hight
extern LIDAR_data *xp_linux_lidar_data_get(void);   //get lidar msg
extern int xp_linux_lidar_send(const char *data,int len); //send data to linux
extern int xp_linux_lidar_send_location(int x,int y,float angle);   //send location message
extern void xp_linux_lidar_location_set(int x,int y,float angle);   //set location msg

extern int xp_linux_lidar_getCorner(void);  //get corner status
extern int xp_linux_lidar_doAngle_get(void); //get do angle state
extern void xp_linux_lidar_doAngle_set(int state);  //set do angle state
extern void xp_linux_lidar_error_set(int state);    //set error state
extern const LIDAR_angle_point *xp_linux_lidar_anglePoint_get(void);    //get angle point
extern const LIDAR_park_msg *xp_linux_lidar_park_get(void); //get lidar park message
extern void xp_linux_lidar_blow(void);  //Blowing lidar surface set
extern void xp_linux_lidar_blow_stop(void); //blowing lidar stop
extern void xp_linux_lidar_blowTime_set(int time);  //set blow hold time
extern int xp_linux_lidar_blowIO_set(int num);  //set blow io pin number
extern void xp_linux_lidar_online_check(void(*lost_deal_fun(void)),int lost_touch); //lidar check and deal
extern int xp_linux_lidar_lost_status(void);    //get lidar lost status

#endif
//end of the file
